In [356]:
import os, geopandas as gpd
In [357]:
edificado=gpd.read_file(os.path.join("maps","zona_edificada","zona_edificada.shp"))
In [358]:
# que tipo es?
type(edificado)
Out[358]:
geopandas.geodataframe.GeoDataFrame
In [359]:
# dimensiones
edificado.shape
Out[359]:
(3, 11)
In [360]:
# nombres de las columnas 
edificado.columns
Out[360]:
Index(['fcode', 'descripcio', 'nam', 'na2', 'acc', 'acc_desc', 'nute', 'txt',
       'shape_leng', 'shape_area', 'geometry'],
      dtype='object')
In [361]:
# contenido
edificado.head()
Out[361]:
fcode descripcio nam na2 acc acc_desc nute txt shape_leng shape_area geometry
0 AL020 Concentración continua ocupada de tiendas o l... QUITO DISTRITO METROPOLITANO None 2 Aproximada 30117001050 Capital de la República del Ecuador 151269.947237 1.956673e+08 POLYGON ((-78.45850 -0.07339, -78.45849 -0.073...
1 AL020 Concentración continua ocupada de tiendas o l... CUENCA None 2 Aproximada 30101001050 Capital Provincial 38325.855028 2.688447e+07 POLYGON ((-78.97261 -2.87888, -78.97261 -2.878...
2 AL020 Concentración continua ocupada de tiendas o l... GUAYAQUIL None 2 Aproximada 30209001050 Capital Provincial 220367.495137 3.009167e+08 POLYGON ((-79.98384 -1.98361, -79.98306 -1.983...
In [362]:
edificado[edificado.isna().any(axis=1)]
Out[362]:
fcode descripcio nam na2 acc acc_desc nute txt shape_leng shape_area geometry
0 AL020 Concentración continua ocupada de tiendas o l... QUITO DISTRITO METROPOLITANO None 2 Aproximada 30117001050 Capital de la República del Ecuador 151269.947237 1.956673e+08 POLYGON ((-78.45850 -0.07339, -78.45849 -0.073...
1 AL020 Concentración continua ocupada de tiendas o l... CUENCA None 2 Aproximada 30101001050 Capital Provincial 38325.855028 2.688447e+07 POLYGON ((-78.97261 -2.87888, -78.97261 -2.878...
2 AL020 Concentración continua ocupada de tiendas o l... GUAYAQUIL None 2 Aproximada 30209001050 Capital Provincial 220367.495137 3.009167e+08 POLYGON ((-79.98384 -1.98361, -79.98306 -1.983...
In [363]:
# tipos
edificado.info()
<class 'geopandas.geodataframe.GeoDataFrame'>
RangeIndex: 3 entries, 0 to 2
Data columns (total 11 columns):
 #   Column      Non-Null Count  Dtype   
---  ------      --------------  -----   
 0   fcode       3 non-null      object  
 1   descripcio  3 non-null      object  
 2   nam         3 non-null      object  
 3   na2         0 non-null      object  
 4   acc         3 non-null      int64   
 5   acc_desc    3 non-null      object  
 6   nute        3 non-null      object  
 7   txt         3 non-null      object  
 8   shape_leng  3 non-null      float64 
 9   shape_area  3 non-null      float64 
 10  geometry    3 non-null      geometry
dtypes: float64(2), geometry(1), int64(1), object(7)
memory usage: 392.0+ bytes
In [364]:
# ploteo
edificado.plot()
Out[364]:
<AxesSubplot:>
In [365]:
vias=gpd.read_file(os.path.join("maps","vias","vias.shp"))
In [366]:
vias.plot()
Out[366]:
<AxesSubplot:>
In [367]:
aeropuertos=gpd.read_file(os.path.join("maps","aeropuertos","aeropuertos.shp"))
In [368]:
aeropuertos.plot()
Out[368]:
<AxesSubplot:>
In [369]:
# ajustes visuales 
In [370]:
edificado.plot(facecolor="violet",edgecolor='black',linewidth=0.1)
Out[370]:
<AxesSubplot:>
In [371]:
vias.plot(edgecolor='mediumaquamarine', linewidth=0.6,linestyle='solid')
Out[371]:
<AxesSubplot:>
In [372]:
aeropuertos.plot(marker='.',color='mediumpurple',markersize=12)
Out[372]:
<AxesSubplot:>
In [373]:
#multiples capas de mapas 
In [374]:
edificado.crs
Out[374]:
<Geographic 2D CRS: EPSG:4326>
Name: WGS 84
Axis Info [ellipsoidal]:
- Lat[north]: Geodetic latitude (degree)
- Lon[east]: Geodetic longitude (degree)
Area of Use:
- name: World
- bounds: (-180.0, -90.0, 180.0, 90.0)
Datum: World Geodetic System 1984
- Ellipsoid: WGS 84
- Prime Meridian: Greenwich
In [375]:
vias.crs
Out[375]:
<Geographic 2D CRS: EPSG:4326>
Name: WGS 84
Axis Info [ellipsoidal]:
- Lat[north]: Geodetic latitude (degree)
- Lon[east]: Geodetic longitude (degree)
Area of Use:
- name: World
- bounds: (-180.0, -90.0, 180.0, 90.0)
Datum: World Geodetic System 1984
- Ellipsoid: WGS 84
- Prime Meridian: Greenwich
In [376]:
aeropuertos.crs
Out[376]:
<Geographic 2D CRS: EPSG:4326>
Name: WGS 84
Axis Info [ellipsoidal]:
- Lat[north]: Geodetic latitude (degree)
- Lon[east]: Geodetic longitude (degree)
Area of Use:
- name: World
- bounds: (-180.0, -90.0, 180.0, 90.0)
Datum: World Geodetic System 1984
- Ellipsoid: WGS 84
- Prime Meridian: Greenwich
In [377]:
# changing crs in cities and rivers to be the same as countries
vias=vias.to_crs(edificado.crs)
aeropuertos=aeropuertos.to_crs(edificado.crs)
In [378]:
base = edificado.plot(facecolor="white", edgecolor='black', linewidth=0.1,figsize=(12,12))
vias.plot(marker='.', color='mediumorchid', markersize=1,alpha=0.7,ax=base)
aeropuertos.plot(edgecolor='blue', linewidth=0.4,ax=base)
Out[378]:
<AxesSubplot:>
In [379]:
import folium

m = vias.explore(color="red", name="vias")

m = aeropuertos.explore(m=m, color="blue",name="aeropuertos")

m
Out[379]:
Make this Notebook Trusted to load map: File -> Trust Notebook
In [380]:
cuenca=edificado[edificado.nam=='CUENCA']
In [381]:
# recortando la data 
vias_clipped = gpd.clip(gdf=vias,mask=cuenca)
aeropuertos_clipped = gpd.clip(gdf=aeropuertos,mask=cuenca)
In [382]:
# muestro la data recortada 
base = cuenca.plot(facecolor="paleturquoise", edgecolor='black', linewidth=0.4,figsize=(5,5))
vias_clipped.plot(marker='+', color='mediumvioletred', markersize=15,ax=base)
aeropuertos_clipped.plot(edgecolor='blue', linewidth=0.5,ax=base)
Out[382]:
<AxesSubplot:>
In [383]:
cuencaCoord=[-2.90055, -79.00453]
In [384]:
m = vias.explore(location=cuencaCoord,zoom_start=7,tiles='CartoDB positron',color='deeppink',name="vias")
m = aeropuertos.explore(m=m, color="blue",name="aeropuertos")

m
Out[384]:
Make this Notebook Trusted to load map: File -> Trust Notebook
In [385]:
# exportando mapas 

# save the map as image
import matplotlib.pyplot as plt

base = cuenca.plot(facecolor="paleturquoise", edgecolor='black', linewidth=0.4,figsize=(5,5))
map2=vias_clipped.plot(marker='+', color='mediumvioletred', markersize=15,ax=base)
mapEnd=aeropuertos_clipped.plot(edgecolor='blue', linewidth=0.5,ax=base)
plt.savefig(os.path.join("maps",'mapEnd.jpg'))
In [386]:
edificado.to_file(os.path.join("maps","ecuadorMaps.gpkg"), layer='edificado', driver="GPKG")
vias.to_file(os.path.join("maps","ecuadorMaps.gpkg"), layer='vias', driver="GPKG")
aeropuertos.to_file(os.path.join("maps","ecuadorMaps.gpkg"), layer='aeropuertos', driver="GPKG")
In [387]:
ecuadorMaps='https://github.com/vaaleriaa111/geoECUADOR/raw/main/maps/ecuadorMaps.gpkg'
In [388]:
from  fiona import listlayers

listlayers(ecuadorMaps)
Out[388]:
['edificado', 'vias', 'aeropuertos']
In [389]:
edificado=gpd.read_file(ecuadorMaps,layer='edificado')
vias=gpd.read_file(ecuadorMaps,layer='vias')
aeropuertos=gpd.read_file(ecuadorMaps,layer='aeropuertos')
In [390]:
base = edificado.plot(facecolor='gainsboro')
vias.plot(ax=base, markersize=0.1, color='hotpink') 
aeropuertos.plot(ax=base, linewidth=0.5)
Out[390]:
<AxesSubplot:>
In [391]:
# otra info 
primerNivel=gpd.read_file(os.path.join("maps","data","ECU_adm1.shp"))
In [392]:
primerNivel.plot()
Out[392]:
<AxesSubplot:>
In [ ]: